package GUI;

import java.awt.*;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import Messages.MessageAddNewEmployee;

import Messages.MessageGetReportWaitersByDate;
import Messages.MessageGetReportWaitersByDateReply;
import Messages.MessageSavingReply;
import Messages.MessageShowAllEmployees;
import Messages.MessageShowAllEmployeesReply;
import Messages.MessageShowAllWorkHours;
import Messages.MessageShowAllWorkHoursReply;

/**
 * this class creates panel which located in right part of a screen
 * the panel appears after click on employee button of PanelButtons panel 
 * the panel include some functions that handles employee
 *  
 * @author igor,jeka
 *
 */
public class PanelFunctionsEmployees  extends PanelFunctionsEmpty
{

	
	private static final long serialVersionUID = 1L;
	private MainMenu mainMenu;
	private JButton button_addEmployee;
	private JButton button_reportEmployee;
	private JButton button_searchEmployee;
	private JButton button_reportHour;
	
public PanelFunctionsEmployees(MainMenu mm)
{
	super(mm);
	this.mainMenu=mm;
	this.add(get_button_addEmployee());
	this.add(get_button_searchEmployee());
	this.add(get_button_ReportEmployee());
	this.add(get_button_ReportHours() );
}
	
	
	
	
private JButton get_button_addEmployee() 
	{
		if (button_addEmployee == null) 
		{			
			button_addEmployee=new JButton("הוספת עובד חדש");  	
			if(this.mainMenu.getUser().getPermission()==1)
				button_addEmployee.setEnabled(false);
			button_addEmployee.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			
			
			button_addEmployee.setPreferredSize(new Dimension(220, 30));
			
			button_addEmployee.addActionListener(new java.awt.event.ActionListener() 
			   {
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					mainMenu.getContentPane().add(new PfAdd_new_employee(mainMenu), BorderLayout.CENTER);					
					mainMenu.getContentPane().validate();						
				}
			});
		}
		return button_addEmployee;
	}

private JButton get_button_searchEmployee() 
{
	if (button_searchEmployee == null) 
	{			
		button_searchEmployee=new JButton("חיפוש עובד");  
		if(this.mainMenu.getUser().getPermission()==1)
			button_searchEmployee.setEnabled(false);
		button_searchEmployee.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_searchEmployee.setPreferredSize(new Dimension(220, 30));
		
		button_searchEmployee.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				
				MessageShowAllEmployees msgShowEmp=new MessageShowAllEmployees( );
				
				
				try {
					mainMenu.ms.client.sendToServer(msgShowEmp);
					MessageShowAllEmployeesReply result=(MessageShowAllEmployeesReply)mainMenu.ms.client.GetMessage();
					mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
					mainMenu.getContentPane().add(new PfSearch_employee(mainMenu,result.getResult()), BorderLayout.CENTER);					
					mainMenu.getContentPane().validate();
					
					
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
											
			}
		});
	}
	return button_searchEmployee;
}
	
	
	
	
private JButton get_button_ReportEmployee() 
	{
		if (button_reportEmployee == null) 
		{			
			button_reportEmployee=new JButton("דוח מכירות");
			if(this.mainMenu.getUser().getPermission()==1)
				button_reportEmployee.setEnabled(false);
			button_reportEmployee.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
			button_reportEmployee.setPreferredSize(new Dimension(220, 30));
			
			button_reportEmployee.addActionListener(new java.awt.event.ActionListener() 
			   {
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					 Date dat = new Date();
					 DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
					 String   data = df.format(dat);
					 MessageGetReportWaitersByDate msgRep=new MessageGetReportWaitersByDate(data,data);
					try {
						mainMenu.ms.client.sendToServer(msgRep);
						MessageGetReportWaitersByDateReply result=(MessageGetReportWaitersByDateReply)mainMenu.ms.client.GetMessage();
						mainMenu.getContentPane().remove(((BorderLayout)mainMenu.getContentPane().getLayout()).getLayoutComponent(BorderLayout.CENTER));
						mainMenu.getContentPane().add(new PfReportOnSales(mainMenu,result.getReport()), BorderLayout.CENTER);					
						mainMenu.getContentPane().validate();
						
						
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
			});
		}
		return button_reportEmployee;
	}
	
private JButton get_button_ReportHours() 
{
	if (button_reportHour == null) 
	{			
		button_reportHour=new JButton("דוח שעות");
	//	if(this.mainMenu.getUser().getPermission()==1)
	//		button_reportHour.setEnabled(false);
		button_reportHour.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		button_reportHour.setPreferredSize(new Dimension(220, 30));
		
		button_reportHour.addActionListener(new java.awt.event.ActionListener() 
		   {
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				 JOptionPane.showMessageDialog(null,"נא לבחור שורה");
				 
			}
		});
	}
	return button_reportHour;
}




}
